package com.ilxqx.framework.system.converter.attr;

import com.ilxqx.framework.system.enumeration.EntityEnum;
import com.ilxqx.framework.system.enumeration.SysRoleStatusEnum;
import org.springframework.stereotype.Component;

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

/**
 * 系统角色状态枚举类型转换
 * @author venus
 */
@Component
@Converter(autoApply = true)
public class SysRoleStatusConverter implements AttributeConverter<SysRoleStatusEnum, String> {

	/**
	 * Converts the value stored in the entity attribute into the
	 * data representation to be stored in the database.
	 *
	 * @param attribute the entity attribute value to be converted
	 * @return the converted data to be stored in the database
	 * column
	 */
	@Override
	public String convertToDatabaseColumn(SysRoleStatusEnum attribute) {
		return attribute.getValue();
	}

	/**
	 * Converts the data stored in the database column into the
	 * value to be stored in the entity attribute.
	 * Note that it is the responsibility of the converter writer to
	 * specify the correct <code>dbData</code> type for the corresponding
	 * column for use by the JDBC driver: i.e., persistence providers are
	 * not expected to do such type conversion.
	 *
	 * @param dbData the data from the database column to be
	 *               converted
	 * @return the converted value to be stored in the entity
	 * attribute
	 */
	@Override
	public SysRoleStatusEnum convertToEntityAttribute(String dbData) {
		return EntityEnum.getEnum(SysRoleStatusEnum.class, dbData);
	}

}
